package com.firewolf.log.core;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

/**
 * 作者：刘兴
 * 时间:19/2/20
 **/
public class DefaultUserInfoService implements UserInfoService {

    @Autowired
    private LogProperties logProperties;

    @Override
    public String getCurrentUserName() {
        Object username = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getSession().getAttribute(logProperties.getUsernameKey());
        return username == null ? null : username.toString();
    }
}
